﻿using MaxStoreErp.Core.Exceptions;
using MaxStoreShop.Domain.Directories;
using MaxStoreShop.Logic.Services.Directories;
using MaxStoreShop.Logic.ServicesContracts.Directories;
using MaxStoreShop.Logic.Tests.FakeRepositories;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MaxStoreShop.Logic.Tests
{
    [TestClass]
    public class ProductCategoryServiceTests
    {
        [TestMethod]
        public void DeleteProductCategoryShouldNormal()
        {
            CreateInstance().DeleteProductCategory(new ProductCategory {Id=1, Name = "Тест"});
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void DeleteProductCategoryShouldThrowErpRuntimeExceptionIfCategoryIsNull()
        {
            CreateInstance().DeleteProductCategory(null);
        }

        [TestMethod]
        public void SaveProductCategoryShouldNormal()
        {
            CreateInstance().SaveProductCategory(new ProductCategory {Name = "Тест"});
        }

        [TestMethod]
        [ExpectedException(typeof (ErpRuntimeException))]
        public void SaveProductCategoryShouldThrowErpRuntimeExceptionIfCategoryIsNull()
        {
            CreateInstance().SaveProductCategory(null);
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void SaveProductCategoryShouldThrowErpRuntimeExceptionIfNameIsNullOrEmpty()
        {
            CreateInstance().SaveProductCategory(new ProductCategory());
        }

        IProductCategoryService CreateInstance()
        {
            return new ProductCategoryService(new ProductCategoryRepositoryFake());
        }
    }
}
